<%--
  Created by IntelliJ IDEA.
  User: 40167
  Date: 2023/12/16
  Time: 12:40
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html lang="en">
<jsp:include page="head.jsp"></jsp:include>
<body>
<jsp:include page="navbar_head.jsp"></jsp:include>

<div class="container-fluid">
    <jsp:include page="navbar.jsp"></jsp:include>
    <div class="col-md-9 main">
        <form class="main" action="${pageContext.request.contextPath}/admin/schedule_add">
            <div class="form-group">
                <label for="movie">请选择需要放映的电影</label>
                <select name="movie" id="movie">
                    <c:if test="${empty movies}">
                        <option value="" readonly="true">未查询到电影院数据！</option>
                    </c:if>
                    <c:if test="${!empty movies}">
                        <c:forEach var="movie" items="${movies}">
                            <option value="${movie.id}">${movie.name}</option>
                        </c:forEach>
                    </c:if>
                </select>
            </div>
            <div class="form-group">
                <label for="auditorium">请选择播出放映厅</label>
                <select name="auditorium" id="auditorium">
                    <c:if test="${empty auditoriums}">
                        <option value="" readonly="true">未查询到电影院数据！</option>
                    </c:if>
                    <c:if test="${!empty auditoriums}">
                        <c:forEach var="auditorium" items="${auditoriums}">
                            <option value="${auditorium.id}">${auditorium.name}</option>
                        </c:forEach>
                    </c:if>
                </select>
            </div>
            <div class="form-group">
                <label for="actTime">请选择播出日期</label>
                <input type="date" id="actDate" name="actDate" class="form-control" placeholder="请选择放映日期...">
                <label for="actTime">请选择播出时间</label>
                <input type="time" id="actTime" name="actTime" class="form-control" placeholder="请选择放映时间...">
            </div>

            <div id="alert_div" class="alert alert-danger" role="alert">
                <c:if test="${!empty failMsg}">
                    <strong>错误!</strong> ${failMsg}
                </c:if>
            </div>

            <button type="submit" class="btn btn-default" id="submit_btn">确认新增</button>
        </form>
    </div>
    <jsp:include page="script.jsp"></jsp:include>
    <script>
        $(function () {
            if (${empty failMsg}) {
                // 隐藏错误消息提示框
                $("#alert_div").hide();
            }
            $("#submit_btn").click(function () {
                // 验证用户名：必须由字母、数字、下划线、-组成，并且长度为4到16位
                // 获取用户名输入框里的内容
                var movie = $("#movie").val();
                // 使用test方法验证
                if (movie === "") {
                    // 提示用户结果
                    $("#alert_div").html("<strong>数据校验不通过！</strong> 请选择要播出的电影！");
                    $("#alert_div").show();
                    return false;
                }
                var actTime=$("#actTime").val();
                if (actTime<=new Date()){
                    $("#alert_div").html("<strong>数据校验不通过!</strong> 放映时间应大于当前时间！");
                    $("#alert_div").show();
                    return false;
                }

                // 验证姓名：不能为空
                var auditorium = $("#auditorium").val();
                if (auditorium === "") {
                    // 提示用户结果
                    $("#alert_div").html("<strong>数据校验不通过！</strong> 请选择播出的放映厅！");
                    $("#alert_div").show();
                    return false;
                }


                // 验证手机：13xxxxxxxxx
                var capacity = $("#capacity").val();
                if (capacity === "") {
                    // 提示用户结果
                    $("#alert_div").html("<strong>数据校验不通过！</strong> 电影院容量不能为空！");
                    $("#alert_div").show();
                    return false;
                }
            });
        });
    </script>
</body>
</html>
